{% extends "base.html" %}

{% block title %}用户管理{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row mb-4">
        <div class="col">
            <div class="d-flex justify-content-between align-items-center">
                <h2>用户管理</h2>
                <a href="{{ url_for('user.add') }}" class="btn btn-primary">
                    <i class="fas fa-user-plus me-1"></i>添加用户
                </a>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col">
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th>用户名</th>
                                    <th>真实姓名</th>
                                    <th>邮箱</th>
                                    <th>电话</th>
                                    <th>角色</th>
                                    <th>状态</th>
                                    <th>最后登录</th>
                                    <th>创建时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for user in users %}
                                <tr>
                                    <td>{{ user.username }}</td>
                                    <td>{{ user.real_name or '-' }}</td>
                                    <td>{{ user.email }}</td>
                                    <td>{{ user.phone or '-' }}</td>
                                    <td>
                                        <span class="badge bg-{{ 'primary' if user.is_admin else 'secondary' }}">
                                            {{ '管理员' if user.is_admin else '普通用户' }}
                                        </span>
                                    </td>
                                    <td>
                                        <span class="badge bg-{{ 'success' if user.status == 'active' else 'danger' }}">
                                            {{ '正常' if user.status == 'active' else '禁用' }}
                                        </span>
                                    </td>
                                    <td>{{ user.last_login.strftime('%Y-%m-%d %H:%M:%S') if user.last_login else '-' }}</td>
                                    <td>{{ user.created_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                                    <td>
                                        <a href="{{ url_for('user.edit', user_id=user.id) }}" class="btn btn-primary btn-sm">
                                            <i class="fas fa-edit"></i>
                                        </a>
                                        {% if user.id != current_user.id %}
                                        <form action="{{ url_for('user.toggle', user_id=user.id) }}" method="POST" class="d-inline">
                                            <button type="submit" class="btn btn-{{ 'danger' if user.status == 'active' else 'success' }} btn-sm">
                                                <i class="fas fa-{{ 'ban' if user.status == 'active' else 'check' }}"></i>
                                            </button>
                                        </form>
                                        {% endif %}
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %} 